<template>
    <div class="components_edit_modal">
        <el-dialog title="批改作业" :visible.sync="state" :show-close="true" :close-on-click-modal="false">

            <div class="components_btns clearfix">
            <el-button type="primary" size="mini">
                    <i class="iconfont icon-leading-iout"></i>
                    打包下载
                </el-button>
              <!-- <a href="javascript:void(0);" class="btns add" >打包下载</a> -->
            </div>
                <div class="scrollBarX">
                    <el-table :data="studentScoreTable"  border stripe style="width: 100%" class="components_edit_tables">
                        <el-table-column label="序号" type="index" align="center" width="50">
                        </el-table-column>
                        <el-table-column  prop="studentNumber"  label="学号" align="center"></el-table-column>
                        <el-table-column  prop="name"  label="学生姓名"  align="center"></el-table-column>
                        <el-table-column  prop="homeworkFile"  label="作业附件" align="center"></el-table-column>
                        <el-table-column  prop="submitTime"  :formatter="formatTime" label="提交时间" align="center"></el-table-column>
                        <el-table-column  prop="score" width="70"  label="成绩" align="center">
                            <template slot-scope="scope">
                                    <el-input v-model="studentScoreTable[scope.$index].score" clearable>
                                    </el-input>
                            </template> 
                        </el-table-column>
                        <el-table-column  prop="comments"  label="评语" align="center">
                            <template slot-scope="scope">
                                    <el-input v-model="studentScoreTable[scope.$index].comments" clearable>
                                    </el-input>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>


            <div slot="footer" class="dialog-footer">
                <el-button @click="updateStudentScore" type="primary" size="small">确 定</el-button>
                <el-button @click="state = false" size="small">关 闭</el-button>
            </div>

        </el-dialog>
    </div>
</template>

<script>
    import {enums} from '@/constant'
    import { mapGetters } from 'vuex'
    import moment from 'moment'
    import PlUpload from "@/components/common/PlUpload.vue"
    export default {
        components: {
            PlUpload,
        },
        data() {
            return {
                state: false,
                studentScoreTable:[],
                homeworkId:null,
                classId:null
            }
        },
        created() {
            // 查询课程列表集合
            // this.getStudentByHomeworkAndClass();
            // 获取学期列表数据
            // this.getSemesterListByDicts();
        },
        mounted() {},
        computed:{
            ...mapGetters({
                schoolList: 'getSchoolList',
            }),
        },
        methods: {
            // 打开模态框
            showDialog(homeworkId,classId){
                this.state = true;
                this.homeworkId=homeworkId;
                this.classId=classId;
                this.getStudentByHomeworkAndClass(homeworkId,classId);
            },
            getStudentByHomeworkAndClass(homeworkId,classId){
                let self = this;
                self.axios.get(api.homeworkTeacher.queryClassStudent+"?homeworkId="+this.$route.params.id+"&classId="+classId)
                .then((response) => {
                    if(response.data.success){
                        self.studentScoreTable = JSON.parse(JSON.stringify(response.data.data));
                    }else {
                        self.$message.error(response.data.msg);
                    }
                });
            },
            updateStudentScore(){
                let self = this;
                let studentScoreTable = self.studentScoreTable;
                for(let i=0;i<studentScoreTable.length;i++){
                    studentScoreTable[i].classId = this.classId;
                    studentScoreTable[i].homeworkId = this.homeworkId;
                }
                // console.log(JSON.stringify(studentScoreTable));
                self.axios.post(api.homeworkTeacher.updateClassStudent,studentScoreTable)
                .then((response) => {
                        if (response.data.success) {
                            self.$message({
                                type: 'success',
                                message: response.data.msg,
                            });
                            self.$parent.getCorrectClass();
                            self.state = false;
                        } else {
                        self.$message.error(response.data.msg);
                        }
                        
                });
                
            },
             formatTime(row, column, cellValue){
                if(typeof(cellValue)=="undefined"){
                    return "";
                }
              return  moment(cellValue).format('YYYY-MM-DD HH:mm');
            }
        },
    };
</script>
<style>
</style>